/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package TimeRecording.reporting;

import TimeRecording.business.DaisyChainSystem;
import TimeRecording.business.DateRange;
import TimeRecording.tables.Employee;
import java.awt.Image;
import java.util.Date;
import javax.swing.ImageIcon;

/**
 * @author david
 */
public abstract class CalendarIconProvider {

    private static boolean imagesLoaded = false;

    protected static Image missingIcon;
    protected static Image presentIcon;

    protected CalendarIconProvider() {
        if (!imagesLoaded) {
            missingIcon = loadImage("Blank");
            missingIcon = null;
            presentIcon = loadImage("Box");
        }
    }

    protected final Image loadImage(String name) {
        return new ImageIcon(getClass().getResource(
                    "/images/calendar/" + name + ".gif")).getImage();
    }

    public Image getIcon(Employee employee, DateRange range, Date date) {

        date = DaisyChainSystem.cleanDate(date);
        if (date.before(range.getFromDate()) || date.after(range.getToDate())) {
            return missingIcon;
        } else {
            return getIcon(employee, date);
        }
    }

    public abstract Image getIcon(Employee employee, Date date);
}
